package com.hiwan.system.web.log;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.framework.dao.plugin.DataTablesUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hiwan.system.common.base.BaseController;
import com.hiwan.system.pojo.Log;
import com.hiwan.system.service.log.LogService;
import com.hiwan.system.util.DictCacheUtils;
import com.hiwan.system.util.UserCacheUtils;

@Controller
@RequestMapping("/log")
public class LogController extends BaseController {
	@Autowired
	private LogService logService;
	
	/**
	 * 
	 * 日志管理页面
	 */
	@RequestMapping("/query.do")
	public String query() {
		return "log/queryLog";
	}
	
	
	/**
	 * 
	 * 日志列表页面
	 */
	@RequestMapping("/toLogList")
	public String toLogList(Log log,ModelMap model) throws ParseException{
		model.put("log", log);
		return "log/logList";
	}
	
	@RequestMapping("/list")
	public @ResponseBody Map<String, Object> list(Log log){
		List<Log> logList = logService.selectLogList(log);
		List<Object[]> list = new ArrayList<Object[]>();
		for (Log l : logList) {
			Object[] arr = new Object[6];
			arr[0] = l.getTitle();
			//arr[1] = l.getType();
			arr[1]=DictCacheUtils.getDictValue(l.getType(), "D00047");
			arr[2] = l.getCreateDate();
			//arr[3] = l.getCreateBy();
			arr[3]=UserCacheUtils.get(l.getCreateBy()).getUserName();
			arr[4] = l.getRequestUri();
			arr[5] = l.getRequestMethod();
			list.add(arr);
		}
		return DataTablesUtil.buildDataTablesReturn(list);
	}
	
	
}
